import urllib.request
import random

def load_baidu():
    url = "https://www.baidu.com"
    user_agent_list = [
        "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0",
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36",
        "Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11",
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1"
    ]
    # 每次请求的浏览器都是不一样的
    random_user_agent = random.choice(user_agent_list)
    request = urllib.request.Request(url)
    # 增减对应的请求头信息 (User-Agent)
    request.add_header("User-Agent", random_user_agent)
    # 请求数据
    response = urllib.request.urlopen(request)
    # 请求头的信息
    print(request.get_header("User-agent"))

load_baidu()


# User-Agent 模拟真实的浏览器发送的请求    --   百度的批量搜索







